package com.jvtd.eyl.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.jvtd.eyl.R;
import com.jvtd.eyl.bean.binding.BookBean;
import com.jvtd.eyl.ui.main.home.read.ReadActivity;

import java.util.List;

/**
 * 预览工具类
 *
 * 作者:chenlei
 * 时间:2018/11/15 9:37 AM
 */
public class ReadUtils {
    private static volatile ReadUtils instance;
    private List<BookBean> mBookBeans;
    private int mIndex;

    public static ReadUtils getInstance()
    {
        if (instance == null)
            synchronized (ReadUtils.class)
            {
                if (instance == null)
                    instance = new ReadUtils();
            }
        return instance;
    }

    private ReadUtils(){
    }

    public List<BookBean> getBookBeans() {
        return mBookBeans;
    }

    public void setBookBeans(List<BookBean> bookBeans) {
        mBookBeans = bookBeans;
    }

    public int getIndex() {
        return mIndex;
    }

    public void setIndex(int index) {
        mIndex = index;
    }

    /**
     * 预览文件
     * @param mContext 上下文
     * @param bookBeans 书籍列表
     * @param index 当前选择
     */
    public static void readFile(Context mContext, List<BookBean> bookBeans, int index) {
        BookBean bookBean = bookBeans.get(index);
        ReadUtils.getInstance().setBookBeans(bookBeans);
        ReadUtils.getInstance().setIndex(index);
        if (!TextUtils.isEmpty(bookBean.getFileType())){
            mContext.startActivity(ReadActivity.getIntent(mContext));
        }else
            Toast.makeText(mContext, R.string.file_type_error, Toast.LENGTH_SHORT).show();
    }
}
